SHELL   := /bin/bash
BASE    := ${PWD}

#  To use a different compiler, just change the following lines,
#  providing the name of the required compiler and omitting the
#  "-DGFORTRAN" flag. 
FC      := gfortran
FFLAGS  := -O3 -DGFORTRAN
CXX     := g++

vpath %.F90 ${BASE}/src
vpath %.f90 ${BASE}/src


rrfcalc: rrfcalc.F90 rrf_module.o wigner.o
	cd ${FC}/exe; ${FC} ${FFLAGS} $^ -o rrfcalc
	mv ${FC}/exe/rrfcalc bin

test:
	cd tests; ../bin/rrfcalc < test.data

test3j test6j test9j: %: bin/%
	cd tests; ../bin/$@ < $@.data # > $@.out

rrf_module.o wigner.o input.o: %.o: %.F90 exe
	cd ${FC}/exe; ${FC} ${FFLAGS} -c $<

rrf_module.mod wigner.mod input.mod: %.mod: %.o exe
#	cd ${FC}/exe; ${FC} ${FFLAGS} -c $%.F90

bin/test3j bin/test6j bin/test9j: bin/%: %.f90 rrf_module.o wigner.o input.o
	cd ${FC}/exe; ${FC} ${FFLAGS} $^ -o ../../$@
#	cd tests; ../bin/$@ < $@.data > $@.out

wigner.o: rrf_module.mod

clean:
	cd ${FC}/exe; rm *.o *.mod core

exe:
	mkdir -p ${FC}/exe
